﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HA.ModFlow.Controls;
using HA.MT3DMS.DomainLayer;
using System.Globalization;
using HA.ModFlow.Domain.DomainLayer;
using HA.ModFlow.Infrastructure;

namespace HA.ModFlow.Controls.MT3DMSWindows
{
    /// <summary>
    /// winMT3DUnits.xaml 的交互逻辑
    /// </summary>
    public partial class winMT3DUnits : Window
    {
        public winMT3DUnits(BasicTransport basicTransport, Units units = null)
        {
            InitializeComponent();

            if (basicTransport == null)
            {
                this._units = units;
                this._unitsCopy = (Units)units.Clone();
                this.DataContext = _unitsCopy;
            }
            else
            {
                this._basicTransport = basicTransport;

                this._pcUnits = (MTModelOption)basicTransport.ModelOption.Clone();

                this.DataContext = _pcUnits.Units;
            }

            //事件
            this.btnOk.Click += new RoutedEventHandler(btnOk_Click);
            this.btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
        }

        #region  字段与属性

        BasicTransport _basicTransport;

        MTModelOption _pcUnits;

        //全局单位
        Units _units;
        //副本
        Units _unitsCopy;

        #endregion

        #region 事件

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            this.ConformToDataCenter();
            this.DialogResult = true;
            this.Close();

        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 将窗体选择写入模型层
        /// </summary>
        private void ConformToDataCenter()
        {
            if (_basicTransport != null)
            {
                this._basicTransport.ModelOption.Units.Length = this._pcUnits.Units.Length;
                this._basicTransport.ModelOption.Units.Time = this._pcUnits.Units.Time;
                this._basicTransport.ModelOption.Units.Mass = this._pcUnits.Units.Mass;
                this._basicTransport.ModelOption.Units.Concentration = this._pcUnits.Units.Concentration;
            }
            else
            {
                this._units.Length = this._unitsCopy.Length;
                this._units.Time = this._unitsCopy.Time;
                this._units.Mass = this._unitsCopy.Mass;
                this._units.Concentration = this._unitsCopy.Concentration;
            }
        }

        #endregion
    }

    public class LengthToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            LENGTH et = (LENGTH)value;
            return et;
        }
    }

    public class TimeToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            TIME et = (TIME)value;
            return et;
        }
    }

    public class MassToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)value;
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            MASS et = (MASS)value;
            return et;
        }
    }
    public class ConcentrationToIntConvert : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return (int)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            CONCENTRATION et = (CONCENTRATION)value;
            return et;
        }
    }

}
